<?php

/**
 * scale actions.
 *
 * @package    zenino
 * @subpackage scale
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class scaleActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    
  }
	
	public function executeDetermine(sfWebRequest $request)
  {
    $notes = $request->getParameter('notes');
		$this->forwardUnless($notes, 'scale', 'index');
		$this->notes = $this->parseRequest($notes);
		$mode = ZeninoMode::create()->fromNotes($this->notes);
		$this->scale = $mode;
  }
	
	public function executeCompose(sfWebRequest $request)
  {
		$tonic = $request->getParameter('tonic');
		$alt = $request->getParameter('alt');
    $name = $request->getParameter('mode');
		$this->forwardUnless($tonic && $name, 'scale', 'index');
		
		$tonic .= $alt;
		$mode = ZeninoMode::create()->fromName($tonic, $name);
		$this->scale = $mode;
  }
	
	protected function parseRequest($input)
	{
		$input = trim($input);
		// remplacement des espaces par des virgules
		$input = preg_replace('#\s+#', ',', $input);
		// creation du tableau
		return explode(',', $input);
	}
	
}
